<%@page pageEncoding="utf-8" contentType="text/html; charset=utf-8" %>
<%@ include file="/home/include/init_home.jsp" %>
<%@ page import="com.welfare.home.*" %>
<%
	HashBox box = new HashBox(request);	


	/* 공통코드 */
	HashList code003		= CommonUtil.getCodeList("003");	//서비스유형
	HashList code004		= CommonUtil.getCodeList("004");	//제공기관
	HashList code005		= CommonUtil.getCodeList("005");	//교육접수기간
	HashList code006		= CommonUtil.getCodeList("006");	//연령대
	HashList code501		= CommonUtil.getCodeList("501");	//생애주기
	HashList code502		= CommonUtil.getCodeList("502");	//대상특성
	HashList code503		= CommonUtil.getCodeList("503");	//가구유형
	HashList code504		= CommonUtil.getCodeList("504");	//소득구분
	HashList code505		= CommonUtil.getCodeList("505");	//지원형태
	HashList code506		= CommonUtil.getCodeList("506");	//욕구
	HashList code507		= CommonUtil.getCodeList("507");	//교육시간
	HashList code508		= CommonUtil.getCodeList("508");	//교육요일


	
	
	/* 파라미터 */
	//검색종류 k:키워드, s:간편검색, d:상세검색, p:프로그램검색, m:모바일
	String ty					= StringUtil.nvl(request.getParameter("ty"),"k");	
	
	
	/* 키워드검색 */
	String keyword_col			= StringUtil.nvl(request.getParameter("keyword_col"), "service_name");
	String keyword				= StringUtil.nvl(request.getParameter("keyword"));
	
	/* 간편검색 */
	String s_age				= StringUtil.nvl(request.getParameter("s_age"));
	String s_birth				= StringUtil.nvl(request.getParameter("s_birth"));
	String s_family				= box.getCheckedValue("s_family");
	String s_income				= box.getCheckedValue("s_income");
	String s_srch_target		= box.getCheckedValue("s_srch_target");
	
	/* 상세검색 */
	String d_service_type		= box.getCheckedValue("d_service_type");
	String d_owner_code			= box.getCheckedValue("d_owner_code");
	String d_srch_age			= box.getCheckedValue("d_srch_age");
	String d_srch_target		= box.getCheckedValue("d_srch_target");
	String d_srch_family		= box.getCheckedValue("d_srch_family");
	String d_srch_income		= box.getCheckedValue("d_srch_income");
	String d_srch_support		= box.getCheckedValue("d_srch_support");
	String d_srch_needs			= box.getCheckedValue("d_srch_needs");
	
	/* 교육프로그램검색 */
	String p_srch_age			= box.getCheckedValue("p_srch_age");
	String p_prg_period			= box.getCheckedValue("p_prg_period");
	String p_srch_prg_time		= box.getCheckedValue("p_srch_prg_time");
	String p_srch_prg_weekday	= box.getCheckedValue("p_srch_prg_weekday");
	String p_service_name		= StringUtil.nvl(request.getParameter("p_service_name"));
	String p_dept_name			= StringUtil.nvl(request.getParameter("p_dept_name"));


	String order_col			= "hit_count desc, service_id desc";
	
	
	HashMap infos = new HashMap();
	infos.put("ty",				ty);
	infos.put("order_col", 		order_col);
	
	//키워드
	if ("k".equals(ty)) {
		if ("service_name".equals(keyword_col)) {
			infos.put("keyword_col",	keyword_col);
			infos.put("service_name",	keyword);
			infos.put("order_col", 		"hit_count desc, service_id desc");
		} else {
			infos.put("keyword_col",	"");
			infos.put("keyword",		keyword);
			infos.put("order_col", 		"srt, hit_count desc, service_id desc");
		}
	}
	//간편검색
	infos.put("s_age", 			CommonUtil.convertSrchAge(s_age));
	infos.put("s_birth",		s_birth);
	infos.put("s_family",		s_family);
	infos.put("s_income",		s_income);
	infos.put("s_srch_target",	s_srch_target);
	//상세검색
	infos.put("d_service_type", d_service_type);
	infos.put("d_owner_code", 	d_owner_code);
	infos.put("d_srch_age",	 	d_srch_age);
	infos.put("d_srch_target", 	d_srch_target);
	infos.put("d_srch_family", 	d_srch_family);
	infos.put("d_srch_income", 	d_srch_income);
	infos.put("d_srch_support", d_srch_support);
	infos.put("d_srch_needs", 	d_srch_needs);
	//교육프로그램검색
	if (ty.equals("p")) {
		infos.put("service_gubn",	"02");
	}
	infos.put("p_srch_age", 			CommonUtil.convertSrchAgeByCode(p_srch_age));
	infos.put("p_prg_period", 			p_prg_period);
	infos.put("p_srch_prg_time",	 	p_srch_prg_time);
	infos.put("p_srch_prg_weekday", 	p_srch_prg_weekday);
	infos.put("p_service_name", 		p_service_name);
	infos.put("p_dept_name", 			p_dept_name);
	
	
	
	
	infos.put("line_per_page", "10");
	infos.put("curr_page", StringUtil.nvl(request.getParameter("curr_page"), "1"));

	HomeDAO dao 	= new HomeDAO();
	
	HashList list 	= dao.selectServiceList(infos);
	
	
	HashList popupList = CommonUtil.getPopupList();

%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
	<title><%= HOME_NAME %></title>
	<%@ include file="/home/include/cssnjs.jsp"  %>
	<script type="text/javascript">
	$(document).ready(function() {
		$('#s_service_name').focus().select();
		$('#list').find('tr').hover(
				function () { $(this).addClass("hover"); }
			  , function () { $(this).removeClass("hover"); }
			)
			.click(function(){


			});
		$('.chkall').click(function(e) {
			if ($(this).attr('checked') == 'checked') {
				$(this).closest('tr').find('input[type="checkbox"]').each(function() {
					if ($(this).attr('id').indexOf('_all') < 0) {
						$(this).attr('checked', true);
					}
				});
			} else {
				$(this).closest('tr').find('input[type="checkbox"]').each(function() {
					if ($(this).attr('id').indexOf('_all') < 0) {
						$(this).attr('checked', false);
					}
				});
			}
		});
		
	<%	for (int i = 0; i < popupList.size(); i++) {	%>
			if (getCookie("event<%=popupList.get("popup_id",i)%>") != "done" )
			{
				cfOpen('popup.jsp?popup_id=<%=popupList.get("popup_id",i)%>','<%=popupList.get("popup_name",i)%>', <%=popupList.get("popup_width",i)%>, <%=popupList.get("popup_height",i)%>);
			}
	<%	}	%>

	});
	
	
	function fnCheckForm(ty) {
		eval('document.' + ty + 'Form').excel_yn.value = "";
		if (ty == "k") {
			//
		} else if (ty == "s") {
			if (document.sForm.s_age.value == "") {
				alert("나이를 입력하세요");
				return false;
			}
		}
	}


	function fnSearch(currPage) {
		document.<%=ty%>Form.curr_page.value = currPage;
		document.<%=ty%>Form.submit();
	}
	
	
	function fnExcel() {
		document.<%=ty%>Form.excel_yn.value = "Y";
		document.<%=ty%>Form.submit();
		document.<%=ty%>Form.excel_yn.value = "";
	}
	</script>
</head>
<body>
	<div id="Wrap">
		<div class="gnbarea">
            <h2 class="title01"><a href="./search.jsp"><img src="./images/home/title01.gif" alt="맞춤복지 검색 서비스" /></a></h2>
            <div class="serch01">            
	           	<form name="kForm" id="kForm" method="post" action="./search.do" onsubmit="return fnCheckForm('k');">
	           		<input type="hidden" name="curr_page" value=""/>
	           		<input type="hidden" name="excel_yn" value=""/>
	                <fieldset>
	                    <legend>맞춤복지 검색 폼 </legend>
                        <div class="serch02">
                        	<select name="keyword_col" id="keyword_col">
                        		<option value="service_name" <%= StringUtil.selected(keyword_col, "service_name") %> >서비스명</option>
                        		<option value="all"  <%= StringUtil.selected(keyword_col, "all") %>>서비스명+내용</option>
                        	</select>
                      		<input class="textbar01" type="text" name="keyword" title="검색어 입력" value="<%=keyword%>"></input>
                      		<button class="serchButton01" type="submit"></button>
                      		<!-- <input class="serchButton01" type="image"  src="./images/home/btn_search.jpg" alt="검색" /> -->
                        </div>
                    </fieldset>
                </form>
	            <div class="button01">	            
	                   <!-- <span><a href="#n" onclick="$('.simpleView').toggle(); $('.detailView').hide(); $('.programView').hide();">간편검색</a></span> |
	                   <span><a href="#n" onclick="$('.detailView').toggle(); $('.simpleView').hide(); $('.programView').hide();">상세검색</a></span> |
	                   <span><a href="#n" onclick="$('.programView').toggle();$('.detailView').hide(); $('.simpleView').hide();">교육프로그램검색</a></span> -->
	                   <span><a href="#n" onclick="$('.simpleView').toggle(); $('.detailView').hide(); $('.programView').hide();"><img src="./images/home/btn_search_simple.gif"/></a></span>
	                   <span><a href="#n" onclick="$('.detailView').toggle(); $('.simpleView').hide(); $('.programView').hide();"><img src="./images/home/btn_search_detail.gif"/></a></a></span>
	                   <span><a href="#n" onclick="$('.programView').toggle();$('.detailView').hide(); $('.simpleView').hide();"><img src="./images/home/btn_search_program.gif"/></a></a></span>
                </div>
            </div>
		</div>
		<div id="contentsWrap">
            <div class="serchResult">
                <span>검색결과 : <%= StringUtil.toPrice((String)infos.get("total_count")) %>건</span>
                <input class="exeldown" type="image"  src="./images/home/exeldown.gif" alt="엑셀다운로드" onclick="fnExcel()"/>
            </div>
            <!-- 검색 옵션 시작 -->
            <div class="serchWrap01">
            	<!-- 간편 검색 시작 -->
                <div class="searchView simpleView">
	                <h3 class="serchTitle01">간편검색</h3>
	                <div class="optionWrap">
	                	<form name="sForm" id="sForm" method="post" action="./search.do">
	                	<input type="hidden" name="ty" value="s"/>
	           			<input type="hidden" name="curr_page" value=""/>
	           			<input type="hidden" name="excel_yn" value=""/>
		                <table class="serchOption01">
		                    <colgroup>
		                        <col style="width:80px;"></col>
		                        <col></col>
		                    </colgroup>
		                    <tbody>
		                        <tr>
			                        <td><strong>나이</strong></td>
			                        <td><input class="textInput01 r" type="text" name="s_age" value="<%=s_age %>" title="나이입력"></input><span class="textAlign01">세</span></td>
		                        </tr>
		                        <tr>
		                            <td><strong>가구유형</strong></td>
		                            <td><%= CommonUtil.makeCheckBox(code503, "s_family", s_family) %></td>
		                        </tr>
		                        <tr>
		                            <td><strong>소득</strong></td>
		                            <td>
		                                <%= CommonUtil.makeCheckBox(code504, "s_income", s_income) %>                         
		                            </td>
		                        </tr>
		                         <tr>
		                            <td><strong>특이사항</strong></td>	
		                            <td>
		                                 <%= CommonUtil.makeCheckBox(code502, "s_srch_target", s_srch_target) %>                                                  
		                            </td>
		                        </tr>       
		                    </tbody>
		                </table>
		                <!-- 검색버튼 영역 시작 -->                
		                <div class="buttonWrap">
		                    <button class="buttontype01" type="submit"></button>
		                    <button class="buttontype02" type="button" onclick="cfResetForm(this.form)"></button>
		                    <button class="buttontype03" type="button" onclick="$('.simpleView').toggle()"></button>
		                </div>
		                </form>
		                <!-- 검색버튼 영역 종료 -->
	                </div>
                </div>
                <!-- 간편 검색 종료 -->
                <!-- 맞춤 검색 시작 -->
                <div class="searchView detailView">
	                <h3 class="serchTitle01">상세검색</h3>
	                <div class="optionWrap">
	                	<form name="dForm" id="dForm" method="post" action="./search.do">
	                	<input type="hidden" name="ty" value="d"/>
	           			<input type="hidden" name="curr_page" value=""/>
	           			<input type="hidden" name="excel_yn" value=""/>
	                	<table class="serchOption01">
	                        <colgroup>
	                            <col style="width:80px;"></col>
	                            <col></col>
	                        </colgroup>
		                    <tbody>
		                        <tr>
		                            <td><strong>서비스유형</strong></td>
		                            <td>
		                            	<span class="checkbox"><input class="chkall" type="checkbox" id="d_service_type_all" value=""/><label for="d_service_type_all">전체</label></span>
		                            	<%= CommonUtil.makeCheckBox(code003, "d_service_type", d_service_type) %>
		                            </td>
	                            </tr>
	                            <tr>
	                                <td><strong>제공기관</strong></td>
	                                <td>
	                                	<span class="checkbox"><input class="chkall" type="checkbox" id="d_owner_code_all" value=""/><label for="d_owner_code_all">전체</label></span>
		                            	<%= CommonUtil.makeCheckBox(code004, "d_owner_code", d_owner_code) %>
		                            </td>
	                            </tr>
	                            <tr>
	                                <td><strong>생애주기</strong></td>
	                                <td>
	                                	<span class="checkbox"><input class="chkall" type="checkbox" id="d_srch_age_all" value=""/><label for="d_srch_age_all">전체</label></span>
		                            	<%= CommonUtil.makeCheckBox(code501, "d_srch_age", d_srch_age) %>
		                            </td>
	                            </tr>
	                            <tr>
	                                <td><strong>대상특성</strong></td>
	                                <td>
	                                	<span class="checkbox"><input class="chkall" type="checkbox" id="d_srch_target_all" value=""/><label for="d_srch_target_all">전체</label></span>
		                            	<%= CommonUtil.makeCheckBox(code502, "d_srch_target", d_srch_target) %>
		                            </td>
	                            </tr>
	                            <tr>
	                                <td><strong>가구유형</strong></td>
	                                <td>
	                                	<span class="checkbox"><input class="chkall" type="checkbox" id="d_srch_family_all" value=""/><label for="d_srch_family_all">전체</label></span>
		                            	<%= CommonUtil.makeCheckBox(code503, "d_srch_family", d_srch_family) %>
		                            </td>
	                            </tr>
	                            <tr>
	                                <td><strong>소득구분</strong></td>
	                                <td>
	                                	<span class="checkbox"><input class="chkall" type="checkbox" id="d_srch_income_all" value=""/><label for="d_srch_income_all">전체</label></span>
		                            	<%= CommonUtil.makeCheckBox(code504, "d_srch_income", d_srch_income) %>
		                            </td>
	                            </tr>
	                            <tr>
	                                <td><strong>지원형태</strong></td>
	                                <td>
	                                	<span class="checkbox"><input class="chkall" type="checkbox" id="d_srch_support_all" value=""/><label for="d_srch_support_all">전체</label></span>
		                            	<%= CommonUtil.makeCheckBox(code505, "d_srch_support", d_srch_support) %>
		                            </td>
	                            </tr>
	                            <tr>
	                                <td><strong>욕구</strong></td>
	                                <td>
	                                	<span class="checkbox"><input class="chkall" type="checkbox" id="d_srch_needs_all" value=""/><label for="d_srch_needs_all">전체</label></span>
		                            	<%= CommonUtil.makeCheckBox(code506, "d_srch_needs", d_srch_needs) %>
		                            </td>
	                            </tr>                                
		                    </tbody>
	                	</table>
		                <!-- 검색버튼 영역 시작 -->                
		                <div class="buttonWrap">
		                    <button class="buttontype01" type="submit"></button>
		                    <button class="buttontype02" type="button" onclick="cfResetForm(this.form)"></button>
		                    <button class="buttontype03" type="button" onclick="$('.detailView').toggle()"></button>
		                </div>
		                <!-- 검색버튼 영역 종료 -->
		                </form>
	                </div>
                </div>
                <!-- 맞춤 검색 종료 -->
                <!-- 교육프로그램 검색 시작 -->
                <div class="searchView programView">
	                <h3 class="serchTitle01">교육프로그램 검색</h3>
	                <div class="optionWrap">
	                	<form name="pForm" id="pForm" method="post" action="./search.do">
	                	<input type="hidden" name="ty" value="p"/>
	           			<input type="hidden" name="curr_page" value=""/>
	           			<input type="hidden" name="excel_yn" value=""/>
	               	 	<table class="serchOption01">
	                        <colgroup>
	                            <col style="width:80px;"></col>
	                            <col></col>
	                        </colgroup>
	                    <tbody>
	                        <tr>
	                            <td><strong>연령대</strong></td>
	                            <td>
	                            	<span class="checkbox"><input class="chkall" type="checkbox" id="p_srch_age_all" value=""/><label for="p_srch_age_all">전체</label></span>
		                            <%= CommonUtil.makeCheckBox(code006, "p_srch_age", p_srch_age) %>
		                        </td>
	                        </tr>
	                        <tr>
	                            <td><strong>교육기간</strong></td>
	                            <td>
	                            	<span class="checkbox"><input class="chkall" type="checkbox" id="p_prg_period_all" value=""/><label for="p_prg_period_all">전체</label></span>
		                            <%= CommonUtil.makeCheckBox(code005, "p_prg_period", p_prg_period) %>
		                        </td>
	                        </tr>
	                        <tr>
	                            <td><strong>시간대</strong></td>
	                            <td>
	                            	<span class="checkbox"><input class="chkall" type="checkbox" id="p_srch_prg_time_all" value=""/><label for="p_srch_prg_time_all">전체</label></span>
		                            <%= CommonUtil.makeCheckBox(code507, "p_srch_prg_time", p_srch_prg_time) %>
		                        </td>
	                        </tr>
	                        <tr>
	                            <td><strong>요일별</strong></td>
	                            <td>
	                            	<span class="checkbox"><input class="chkall" type="checkbox" id="p_srch_prg_weekday_all" value=""/><label for="p_srch_prg_weekday_all">전체</label></span>
		                            <%= CommonUtil.makeCheckBox(code508, "p_srch_prg_weekday", p_srch_prg_weekday) %>
		                        </td>
	                        </tr>
	                        <tr>
	                            <td><strong>프로그램명</strong></td>
	                            <td><input class="textInput02" type="text" name="p_service_name" value="<%=p_service_name %>" title="프로그램 명 입력"></input></td>                                                                                         
	                        </tr>
	                        <tr>
	                            <td><strong>제공기관명</strong></td>
	                            <td><input class="textInput02" type="text" name="p_dept_name" value="<%=p_dept_name %>" title="제공기관 명 입력"></input></td>                                                                                         
	                        </tr>
	                    </tbody>
	                </table>
	                <!-- 검색버튼 영역 시작 -->                
	                  <div class="buttonWrap">
	                    <button class="buttontype01" type="submit"></button>
	                    <button class="buttontype02" type="button" onclick="cfResetForm(this.form)"></button>
	                    <button class="buttontype03" type="button" onclick="$('.programView').toggle()"></button>
	                </div>
	                <!-- 검색버튼 영역 종료 -->
	                </form>
	                </div>
	            </div>
                <!-- 교육프로그램 검색 종료 -->                
            </div>
            <!-- 검색 옵션 종료 -->
            <table class="serchResult01" summary="유형, 서비스명, 제공기관, 연락처, 조회로 구성된 표">
                <caption>복지 검색 결과</caption>
                <colgroup>
                    <col width="60px;"></col>
                    <col width="285px;"></col>
                    <col width="150px;"></col>
                    <col width=140px;></col>
                    <col width="60px;"></col>
                </colgroup>
                <thead>
                    <tr>
	                    <th scope="col">유형</th>
	                    <th scope="col">서비스 명</th>
	                    <th scope="col">제공기관</th>
	                    <th scope="col">연락처</th>
	                    <th scope="col">조회</th> 
                    </tr>                   
                </thead>
                <tbody id="list">
        	<%	for (int i = 0; i < list.size(); i++) { %>
                    <tr>
                        <td><%= list.get("service_type", i) %></td>
                        <td><a href="./service.jsp?service_id=<%= list.get("service_id", i) %>" target="_blank"><strong><%= list.get("service_name", i) %></strong></a></td>
                        <td><span><%= list.get("dept_name", i) %></span></td>
                        <td><%= list.getToBr("tel_no", i) %></td>
                        <td><%= list.get("hit_count", i) %></td>
                    </tr>
           	<%	} %>              
                </tbody>
            </table>
            
            <% 	if (list.size() == 0) { %>
            <!-- 검색결과 없음 시작 -->
            <div id="nodata">
            	<p>입력하신 조건에 일치하는 검색결과가 없습니다.</p>
            </div>
            <!-- 검색결과 없음 종료 -->
            <%	} %>
            
            
            <% 	if (list.size() > 0) { %>
            <!-- 페이징 시작 -->                
            <div class="pagination">
                <%= StringUtil.getPageHtml(infos) %>
            </div>
            <!-- 페이징 종료 -->          
            <%	} %>      
		</div>
		<div id="banner">
			<a href="http://www.bokjiro.go.kr" target="_blank" title="새창으로 열림"><img src="./images/home/logo_bokjiro.gif"/></a>
			&nbsp; <img  src="./images/home/logo_callcenter.gif" alt="행복콜센터02-330-1004" />
			&nbsp; <a href="http://www.bokjiro.go.kr/gowf/wel/welsvc/imtcalc/WelImtCalcMain.do" target="_blank" title="새창으로 열림"><img src="./images/home/logo_calculate.gif"/></a>
		</div>
		<div id="footer">
			
			     <div class="footerLogo01">
			         <img src="./images/home/footerlogo.gif" alt="서대문구 로고" />
			     </div>
			     <div class="footerAddr">
			         <address>서울 서대문구 연희로 248 (연희동) 서대문구청 3층 복지정책과 <br /> 대표전화 : 02-330-8744 | 이메일 : <a href="mailto:ssuney84@sdm.go.kr" >ssuney84@sdm.go.kr</a></address>
			     </div>
		     <div class="footerCall">
		     	
		     </div>
		</div>			
	</div>

</body>








</html>
